<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Dispatch LookUp</title>
<link href="UniversalStyleSheet.css" rel="stylesheet" type="text/css" />
<%'connections
dim rs,db
set db=server.CreateObject("adodb.connection")
set rs=server.CreateObject("adodb.recordset")
filepath="c:\Alpha Page\Front End\afterhours_be.mdb" 'server.MapPath("/afterhours/access/backend/afterhours_be.mdb")
if request.QueryString("TheDay")="" then
	theday=weekdayname(weekday(now()))
else
	theday=request.QueryString("TheDay")
end if

db.open ("provider=microsoft.jet.oledb.4.0;data source=" & filepath)

'get week
sql="week"
rs.open sql,db,1,2
weekRA=rs.getrows()
rs.close

if request.QueryString("ZipCode")<>"" then
	'get city
	sql="select city from [colorado zipcodes] where zip=" & request.QueryString("Zipcode")
	rs.open sql,db,1,2
	if not rs.eof then
		city=rs("city")
	else
		city="(unknown ZipCode)"
	end if
	rs.close
	
	'get HVAC
	sql="select contractor,code from [q_Zips_and_Days] where zip=" & request.QueryString("ZipCode") & " and " & theday & "=yes and [hvac sp]=yes order by rank desc, [contractor]"
	rs.open sql,db,1,2
	if not rs.eof then
		hvacRA=rs.getrows()
	else
		redim hvacRA(0,0)
		hvacRA(0,0)="No On Call"
	end if
	rs.close
	
	'get appliance
	sql="select contractor,code from [q_Zips_and_Days] where zip=" & request.QueryString("ZipCode") & " and " & theday & "=yes and [appliance sp]=yes order by rank desc, [contractor]"
	rs.open sql,db,1,2
	if not rs.eof then 
		appRA=rs.getrows()
	else
		redim appRA(0,0)
		appRA(0,0)="No On Call"
	end if
	rs.close
end if


db.close
set rs=nothing
set db=nothing
%>

<script type="text/javascript" language="javascript">
function zipcode_change()
{
d=document.getElementById("WeekDay")
z=document.getElementById("ZipCode")
wd=d.options[d.selectedIndex].value
query="?TheDay=" + wd + "&ZipCode=" + z.value
window.location.href="DispatchLookUp.asp" + query
}

function weekday_change()
{
//alert("weekday change")
d=document.getElementById("WeekDay")
z=document.getElementById("ZipCode")
wd=d.options[d.selectedIndex].value
query="?TheDay=" + wd + "&ZipCode=" + z.value
window.location.href="DispatchLookUp.asp" + query
}

function showContractor(contractor,camefrom)
{
hv=document.getElementById("HVAC")
ap=document.getElementById("Appliance")

if(camefrom=="link")
	{
	hv.selectedIndex=-1
	ap.selectedIndex=-1
	}
if(camefrom=="hvac")
	{
	ap.selectedIndex=-1
	}
if(camefrom=="appliance")
	{
	hv.selectedIndex=-1
	}
d=document.getElementById("WeekDay")
theday=d.options[d.selectedIndex].value
url="ContractorDetails.asp?theday=" + theday + "&contractor=" + contractor
cd=document.getElementById("ContractorDetails")
cd.src=url
}

</script>
</head>

<body>

<table width="1000" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="20" height="20" background="Images/TableUpperLeft.png"></td>
    <td width="960" height="20" background="Images/TableUpperMiddle.png"></td>
    <td width="20" height="20" background="Images/TableUpperRight.png"></td>
  </tr>
  <tr>
    <td width="20" background="Images/TableMiddleLeft.png"></td>
    <td bgcolor="#FFFFFF">
	<table width="957" border="0" cellpadding="0" cellspacing="1" bgcolor="#009900">
      <tr>
        <td width="112" align="center" valign="top" bgcolor="#FFFFFF" class="ResultsAddress">Data Shown Is For:<br />
          
		  <select name="WeekDay" size="7" id="WeekDay" onchange="javascript: weekday_change()" style="background-color:#FFFF99">
          <% 
		  for x=0 to ubound(weekRA,2)
		  	if theday=weekdayname(weekday(weekRA(0,x))) then 
				selected="selected='selected'"
		  	else
				selected=""
			end if 
			
			response.Write("<option value='" & weekdayname(weekday(cdate(weekRA(0,x)))) &"' " & selected & ">" & weekdayname(weekday(cdate(weekRA(0,x)))) & " " & weekRA(0,x) & "</option>" )
		  next
		  %>
		   </select>
		  <br />
		  <br />
		  <a href="#" onclick="javascript: showContractor('999','link')" >No On-Call Instructions</a> 
		  </td>
        <td width="58" align="center" valign="top" bgcolor="#FFFFFF" class="SearchFormText">
	    <form id="ZipForm" name="ZipForm" method="post" action="javascript: zipcode_change()">
          <span class="ResultsAddress">ZipCode </span><br />
          <input name="ZipCode" type="text" id="ZipCode" tabindex="1" size="7"  value="<%= request.QueryString("ZipCode") %>" style="background-color:#FFFF99"/>
            </form>
		  	<% if request.QueryString("ZipCode")<>"" then %>
		  		<span class="ResultsName"><%= city %></span>
			<% end if %>
		  </td>
        
		<td width="108" align="center" valign="top" bgcolor="#FFFFFF" class="ResultsAddress">HVAC
			<br/>
           	<span class="SearchFormText">(furnace,AC,<br />
           	WaterHeater)</span>
			<br/>
           	<select name="HVAC" size="6" id="HVAC" style="background-color:#FFFF99" onchange="javascript: showContractor(this.options[this.selectedIndex].value,'hvac')">
          	<%'hvac list
		  	if request.QueryString("ZipCode")<>"" then
				if ubound(hvacRA)>0 then 
		  			for x=0 to ubound(hvacRA,2)
		  				response.Write("<option value='" & hvacRA(1,x) & "'>" & hvacRA(0,x) & "</option>")
					next
				else
					response.Write("<option value='999'>(No OnCall For " & request.QueryString("ZipCode") & ")</option>")
				end if
			end if
		  	%>
		  	</select>		</td>
		  
        <td width="94" align="center" valign="top" bgcolor="#FFFFFF" class="ResultsAddress">Appliance
        	<br/>
          	<span class="SearchFormText">(fridge,washer,<br />
          	etc.)</span>
          	<br/>  
            <select name="Appliance" size="6" id="Appliance" style="background-color:#FFFF99" onchange="javascript: showContractor(this.options[this.selectedIndex].value,'appliance');">
			<%'appliance list
		 	if request.QueryString("ZipCode")<>"" then 
		  		'response.Write("<option>" & ubound(appRA) & "</option>")
				if ubound(appRA)>0 then
					for x=0 to ubound(appRA,2)
						response.Write("<option value='" & appRA(1,x) & "'>" & appRA(0,x) & "</option>")
					next
				else
					response.Write("<option value='999'>(No OnCall For " & request.QueryString("ZipCode") & ")</option>")
				end if
		 	end if
		  	%>
            </select>          
			</td>
        <td width="17" align="center" valign="top" bgcolor="#D2FFD2"></td>
        <td width="560" align="center" valign="top" bgcolor="#FFFFFF" >
		<iframe src="ContractorDetails.asp" id="ContractorDetails" name="ContractorDetails" height="285" width="540" scrolling="no" frameborder="0"></iframe>		</td>
      </tr>
    </table></td>
    <td width="20" background="Images/TableMiddleRight.png"></td>
  </tr>
  <tr>
    <td width="20" height="20" background="Images/TableLowerLeft.png"></td>
    <td width="960" height="20" background="Images/TableLowerMiddle.png"></td>
    <td width="20" height="20" background="Images/TableLowerRight.png"></td>
  </tr>
</table>
</body>
</html>
